 package net.go176.backpack.core.mcp9_0;
 
 import baubles.common.container.InventoryBaubles;
 import baubles.common.lib.PlayerHandler;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import net.go176.backpack.core.MyDataHandlerGUI;
import net.go176.backpack.util.MCPUtil;
import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.inventory.IInventory;
 import net.minecraft.item.ItemStack;
 import net.minecraft.nbt.CompressedStreamTools;
 import net.minecraft.nbt.NBTBase;
 import net.minecraft.nbt.NBTTagCompound;
 import net.minecraft.nbt.NBTTagList;

import net.go176.backpack.Backpack;

 import net.go176.backpack.gui.InventoryType;

 import net.go176.backpack.util.NMSUtil;
 import org.bukkit.entity.Entity;
 import org.bukkit.entity.HumanEntity;
 import org.bukkit.entity.Player;
 import org.bukkit.inventory.Inventory;
 import org.bukkit.inventory.ItemStack;
 
 public class BaublesHandler
   extends MyDataHandlerGUI {
   public BaublesHandler(Backpack plugin) {
     super(plugin);
   }
 
   
   public InventoryType getInventoryType() {
     return InventoryType.Baubles_Inventory;
   }
 
   
   public void saveData(File file, Player player) throws IOException {
     if (!this.cfgMan.multi_Baubles_Inventory)
       return; 
     File filetmp = new File(String.valueOf(file.getPath()) + ".tmp");
     EntityPlayer nms_player = (EntityPlayer)NMSUtil.getNMSEntity((Entity)player);
     InventoryBaubles inv = PlayerHandler.getPlayerBaubles(nms_player);
     NBTTagCompound nbt = new NBTTagCompound();
     inv.saveNBT(nbt);
     FileOutputStream output = new FileOutputStream(filetmp);
     try {
       CompressedStreamTools.func_74799_a(nbt, output);
     } finally {
       output.close();
     } 
     if (file.exists())
       file.delete(); 
     filetmp.renameTo(file);
   }
 
   
   public void loadData(File file, Player player) throws IOException {
     if (!this.cfgMan.multi_Baubles_Inventory)
       return; 
     EntityPlayer nms_player = (EntityPlayer)NMSUtil.getNMSEntity((Entity)player);
     InventoryBaubles inv = new InventoryBaubles(nms_player);
     if (file.exists() && file.isFile()) {
       NBTTagCompound nbt; FileInputStream fileinputstream = new FileInputStream(file);
       
       try {
         nbt = CompressedStreamTools.func_74796_a(fileinputstream);
       } finally {
         fileinputstream.close();
       } 
       inv.readNBT(nbt);
     } 
     PlayerHandler.setPlayerBaubles(nms_player, inv);
   }
 
   
   public void readOnlineInv(Inventory inv, Player player) {
     EntityPlayer nms_player = (EntityPlayer)NMSUtil.getNMSEntity((Entity)player);
     IInventory nms_inv = (IInventory)NMSUtil.getNMSInventory(inv);
     InventoryBaubles nms_sourceInv = PlayerHandler.getPlayerBaubles(nms_player);
     MCPUtil.readInventory(nms_inv, (IInventory)nms_sourceInv);
   }
 
   
   public void onUpdateOnlineInv(Inventory inv, Player target, HumanEntity viewer) {
     EntityPlayer nms_player = (EntityPlayer)NMSUtil.getNMSEntity((Entity)target);
     IInventory nms_inv = (IInventory)NMSUtil.getNMSInventory(inv);
     InventoryBaubles nms_sourceInv = PlayerHandler.getPlayerBaubles(nms_player);
     MCPUtil.writeInventorySafely(nms_inv, (IInventory)nms_sourceInv, viewer);
   }
 
   
   public void loadOfflineInv(Inventory inv, File file) throws IOException {
     InventoryBaubles nms_inv = new InventoryBaubles(null);
     NBTTagCompound nbt = MCPUtil.readNBTfromFile(file);
     nms_inv.readNBT(nbt);
     ItemStack[] stackList = nms_inv.stackList;
     for (int i = 0; i < stackList.length; i++) {
       inv.setItem(i, NMSUtil.asCraftMirror(stackList[i]));
     }
   }
 
 
 
 
 
 
 
 
   
   public void onCloseOfflineInv(Inventory inv, File file) throws IOException {
     NBTTagCompound nbt = MCPUtil.readNBTfromFile(file);
     ItemStack[] contents = inv.getContents();
     NBTTagList nbtlist = new NBTTagList();
     for (int i = 0; i < 4; i++) {
       if (contents[i] != null) {
         NBTTagCompound nbt1 = new NBTTagCompound();
         nbt1.func_74774_a("Slot", (byte)i);
         ((ItemStack)NMSUtil.asNMSCopy(contents[i])).func_77955_b(nbt1);
         nbtlist.func_74742_a((NBTBase)nbt1);
       } 
     } 
     nbt.func_74782_a("Baubles.Inventory", (NBTBase)nbtlist);
     File filetmp = new File(String.valueOf(file.getPath()) + ".tmp");
     FileOutputStream output = new FileOutputStream(filetmp);
     try {
       CompressedStreamTools.func_74799_a(nbt, output);
     } finally {
       output.close();
     } 
     if (file.exists())
       file.delete(); 
     filetmp.renameTo(file);
   }
 }


/* Location:              D:\User\Xuan\Downloads\MyBackpack1.2.5.jar!\net\saralab\mybackpack\core\mcp9_0\BaublesHandler.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.1.3
 */